import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/logistics_controller/logistics_page_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/vo/logistics_vo.dart';

class LogisticsPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    Map<String, dynamic> argumentsMap = Get.arguments;
    String image = argumentsMap['image'];
    String title = argumentsMap['title'];
    String price = argumentsMap['price'];
    String trackingNumber = argumentsMap['trackingNumber'];
    String companyTitle = argumentsMap['companyTitle'];
    return Scaffold(
      body: Column(
        children: [
          Stack(
            children: [
              Container(
                height: 200.h + ScreenUtil().statusBarHeight,
                width: 375.w,
                alignment: Alignment.topCenter,
                child: Container(
                  width: 375.w,
                  height: 108.h + ScreenUtil().statusBarHeight,
                  alignment: Alignment.topCenter,
                  padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      colors: [
                        seckillPageHead1,
                        seckillPageHead2
                      ]
                    )
                  ),
                  child: Stack(
                    children: [
                      Container(
                        alignment: Alignment.center,
                        height: 44.h,
                        child: Text(
                          '物流信息',
                          style: TextStyle(
                            color: textWhiteColor,
                            fontSize: 20.sp
                          ),
                        ),
                      ),
                      Positioned(
                        left: 12.w,
                        child: InkWellUtil.shakeProofInkWell(Container(
                          height: 44.w,
                          alignment: Alignment.center,
                          child: Image.asset(
                            'assets/icons/icon_back_w.png',
                            width: 24.w,
                            height: 24.w,
                          ),
                        ), () {
                          Get.back();
                        }),
                      )
                    ],
                  ),
                ),
              ),
              Positioned(
                bottom: 0,
                child: Container(
                  width: 375.w,
                  height: 157.h,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image.asset(
                        'assets/icons/icon_logistics_bg.png',
                        width: 358.w,
                        height: 34.h,
                        fit: BoxFit.cover,
                      ),
                      Container(
                        height: 123.h,
                        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.w),
                        decoration: BoxDecoration(
                          color: bgWhiteColor,
                          borderRadius: BorderRadius.vertical(top: Radius.circular(5.w))
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            NetworkImageUtil(
                              url: image, 
                              width: 90.w, 
                              height: 90.w,
                              borderRadius: 5.w,
                            ),
                            SizedBox(width: 12.w),
                            Expanded(child: Container(
                              constraints: BoxConstraints(
                                minHeight: 90.w
                              ),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.start,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    title,
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                      color: textBlackColor,
                                      fontSize: 14.sp
                                    ),
                                  ),
                                  SizedBox(height: 12.h),
                                  Text(
                                    '¥$price',
                                    style: TextStyle(
                                      color: textBlackColor,
                                      fontSize: 12.sp
                                    ),
                                  ),
                                ],
                              ),
                            ))
                          ],
                        ),
                      )
                    ],
                  ),
                )
              )
            ],
          ),
          Container(
            height: 12.h,
            color: pageBgColor,
          ),
          Expanded(child: GetBuilder<LogisticsPageController>(
            init: LogisticsPageController(),
            builder: (controller) {
              return ScrollConfigurationCommon(child: SingleChildScrollView(
                child: Column(
                  children: [
                    Container(
                      padding: EdgeInsets.symmetric(horizontal: 12.w),
                      child: Container(
                        height: 51.h,
                        padding: EdgeInsets.symmetric(horizontal: 4.w),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: lineColor,
                              width: .5
                            )
                          )
                        ),
                        child: Row(
                          children: [
                            Image.asset(
                              'assets/icons/icon_logistics.png',
                              width: 24.w,
                              height: 24.w,
                            ),
                            SizedBox(width: 8.w),
                            Expanded(child: Text(
                              '$companyTitle $trackingNumber',
                              style: TextStyle(
                                color: textBlackColor,
                                fontSize: 14.sp,
                              ),
                            )),
                            Container(
                              margin: EdgeInsets.only(left: 10.w),
                              child: InkWellUtil.shakeProofInkWell(Text(
                                '复制',
                                style: TextStyle(
                                  color: mainTextColor,
                                  fontSize: 12.sp
                                ),
                              ), () {
                                Clipboard.setData(ClipboardData(text: trackingNumber));
                                EasyLoading.showToast('复制成功');
                              }),
                            )
                          ],
                        ),
                      ),
                    ),
                    Container(
                      height: 49.h,
                      padding: EdgeInsets.symmetric(horizontal: 16.w),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '物流动态',
                        style: TextStyle(
                          color: textSubtitleColor,
                          fontSize: 12.sp
                        ),
                      ),
                    ),
                    Column(
                      children: controller.logisticsData.value.list!.asMap().keys.map((index) {
                        return _buildLogisticsItem(controller.logisticsData.value.list![index], index, controller.logisticsData.value.list!.length);
                      }).toList(),
                    )
                  ],
                ),
              ));
            },
          ))
        ],
      ),
    );
  }


  Widget _buildLogisticsItem(LogisticsItem logisticsItem, int index, int length) {
    return Stack(
      children: [
        Container(
          width: 375.w,
          padding: EdgeInsets.only(left: 28.w, right: 16.w),
          child: Container(
            padding: EdgeInsets.only(left: 25.w, bottom: 16.h),
            decoration: BoxDecoration(
              border: Border(
                left: index + 1 < length ?  BorderSide(
                  color: lineColor,
                  width: 1
                ) : BorderSide.none
              )
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '${logisticsItem.context}',
                  style: TextStyle(
                    color: textBlackColor,
                    fontSize: 14.sp
                  ),
                ),
                SizedBox(height: 2.h),
                Text(
                  '${logisticsItem.time}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 12.sp
                  ),
                )
              ],
            ),
          ),
        ),
        Positioned(
          left: index == 0 ? 16.w : 20.w,
          child: index == 0 ? Image.asset(
            'assets/icons/icon_point.png',
            width: 24.w,
            height: 24.w,
          ) : Image.asset(
            'assets/icons/icon_point_w.png',
            width: 16.w,
            height: 16.w,
          )
        )
      ],
    );
  }
}